<?php

namespace App\Model;


use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class Device extends BaseModel
{
    protected $connection = 'api';
    protected $table = 'device';

    /*
     * $channel_id 渠道id []
     * $type  iphone android
     * $timestamp [111,111]
     * $limit  = 10
     * */
    public function getList($channel_id, $type, $timestamp, $idfa = '', $limit = 10)
    {
        $where[] = ['idfa','!=',''];
        if ($idfa) {
            $where['idfa'] = $idfa;
        }
        $res = DB::connection($this->connection)->table($this->table)
            ->whereIn('channel_id', $channel_id)
            ->whereIn('os_name', $type)
            ->where($where)
            ->whereBetween('created_at', $timestamp)
            ->orderBy('created_at', 'desc')
            ->paginate($limit);
        return $this->objToArray($res);
    }
}